<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Purchase extends Model
{
    protected $table = 'purchases';
    protected $fillable = [
        'company',
        'codeno',
        'status',
        'all_price',
        'purchase_nums',
        'remark',
        'created_at'
    ];
     public function purchase_item(){
        return $this->hasMany('App\PurchaseItem');
    }
     public function scopeAllOrSearch($query,$searchQuery = null)
    {
        if (is_null($searchQuery)) {
            return $query->paginate(config('admin.purchase.perpage'));
        }else{
            $search="%{$searchQuery}%";
            return $query->where('company','like',$search)
                    ->orWhere('codeno', 'like', $search)
                    ->paginate(config('admin.purchase.perpage'));
        }
    }
}
